import { ref, watch } from 'vue'
export default class Protect {
  constructor() {
    let defaultOptions = {
      A: [], //甲值
      B: new Array(60).fill(0).map((res, k) => k + 1), //level
      diffA: ref(400), //减值
      rate: 5 //级别
    }

    this.options = defaultOptions
    this.results = []

    watch(defaultOptions.diffA, () => {
      this.init()
    })
    this.init()
  }
  init() {
    this.options.A = []
    for (var i = 0; i < this.options.rate; i++) {
      this.options.A.push((i + 1) * this.options.diffA.value)
    }
    let { A, B, diffA } = this.options
    let results = []
    for (var i = 0; i < A.length; i++) {
      let a_num = A[i]
      for (var j = 0; j < B.length; j++) {
        let b_num = B[j]
        let result = this.calRate(a_num, b_num)
        results.push({
          a_num,
          b_num,
          result
        })
      }
    }
    this.results = results
  }
  calRate(a, b) {
    let origin = a / (a + b * 85 + 400)
    a = a - this.options.diffA.value
    let diff = a / (a + b * 85 + 400)
    return {
      origin: Math.floor(origin.toFixed(2) * 100),
      diff: Math.floor(diff.toFixed(2) * 100),
      grow: Math.floor((origin - diff).toFixed(2) * 100)
    }
  }
}
